﻿#include "dbhelper.h"
#include "panel.h"
#include "g_function.h"

//#include <QApplication>
#include <QtSingleApplication>

int main(int argc, char *argv[])
{
    QtSingleApplication a(argc, argv);

    if(argc == 2)
    {
        if(sp_parseCommand(argv[1]))
            return EXIT_SUCCESS;
    }
    else
        sp_createRunFile();

    if(a.isRunning())
    {
        QMessageBox::critical(0,QStringLiteral("已经在运行"),QStringLiteral("已经有一个实例在运行中！"),
                              QMessageBox::Ok);
        return EXIT_SUCCESS;
    }

    if(!createConnection())
    {
        QMessageBox::critical(0,QStringLiteral("致命错误"),QStringLiteral("无法连接到数据库！"),
                              QMessageBox::Ok);
        return -1;
    }

    Panel w;
    a.setActivationWindow(&w);
    w.show();

    return a.exec();
}
